package phan.connection;

import phan.connection.StringFormat;
import java.sql.SQLException;
import java.util.Date;
import java.util.*;
import phan.connection.MySQLDBConnector;

public class ModifierCoordonneesBean {

    private static String DATE_FORMAT_PATTERN = "yyyy-MM-dd";
   
    private Hashtable errors;
    private String login;

    private String nom;
    private String prenom;
    private String email;
    private String adress;
    private String ville;
    private String postal;
    private String pays;
    private String tel;
    private String description;
    private String an;
    private String jour;
    private String mois;
    private String numero;
   
//***********************************************

    public boolean validate() {

        MySQLDBConnector con = new MySQLDBConnector();
        boolean exist = con.checkUserName(login);
        boolean allOk = true;
        int annee = 0;
        // String selected=isRbSelected(notify);
        if (!getAn().equals("") && getAn() != null) {
            annee = Integer.parseInt(getAn());
        }
        boolean sup18 = isSup18(annee);

        if (sup18 && !getAn().equals("")) {
            System.out.println(" < 18 ans");
            errors.put("an", "Vous avez moins de 18 ans");
            allOk = false;
        }
        if (getAn().equals("")) {
            System.out.println("An = null");
            errors.put("an", "Entrer votre date de naissance");
            allOk = false;
        }
        if (getAn().equals("")) {
            System.out.println("An = null");
            errors.put("an", "Entrer votre date de naissance");
            allOk = false;
        } 
        
        if (mois.equals("13")) {
            errors.put("mois", "Choisir votre mois de naissance SVP ! ");
            mois = "";
            allOk = false;
        }
        
       
        if (nom.equals("")) {
            errors.put("nom", "Entrer votre nom SVP ! ");
            nom = "";
            allOk = false;
        }
        if (prenom.equals("")) {
            errors.put("prenom", "Entrer votre prenom SVP ! ");
            prenom = "";
            allOk = false;
        }
        if (email.equals("") || (email.indexOf('@') == -1)) {
            errors.put("email", "Entrer un  email valide SVP ! ");
            email = "";
            allOk = false;
        }
        if (adress.equals("")) {
            errors.put("adress", "Entrer votre adresse SVP ! ");
            adress = "";
            allOk = false;
        }
        if (ville.equals("")) {
            errors.put("ville", "Entrer la ville SVP ! ");
            ville = "";
            allOk = false;
        }
        if (pays.equals("")) {
            errors.put("pays", "Entrer le champs pays SVP ! ");
            pays = "";
            allOk = false;
        }
        if (tel.equals("")) {
            errors.put("tel", "Entrer votre téléphone ! ");
            tel = "";
            allOk = false;
        }
      
       
        
       
        if (postal.equals("") || postal.length() != 5) {
            errors.put("postal", "Entrer le code postal valide");
            postal = "";
            allOk = false;
        
        }
        return allOk;
    }

    public String getErrorMsg(String s) {
        String errorMsg = (String) errors.get(s.trim());
        return (errorMsg == null) ? "" : errorMsg;
    }

    public void setErrors(String key, String msg) {
        errors.put(key, msg);
    }


//************************************************
    public ModifierCoordonneesBean() {
        numero="";
        an = "";
        nom = "";
        prenom = "";
        email = "";
        adress = "";
        ville = "";
        pays = "";
        tel = "";
        login = "";
       
        postal = "";
      
       
        errors = new Hashtable();

    }

    public String getNom() {
        return this.nom;
    }

    public void setNom(String valeur) {
        this.nom = valeur;
    }

    public String getPrenom() {
        return this.prenom;
    }

    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }

   

    public String getLogin() {
        return this.login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAdress() {
        return this.adress;
    }

    public void setAdress(String adr) {
        this.adress = adr;
    }

    public String getPostal() {
        return this.postal;
    }

    public void setPostal(String pos) {
        this.postal = pos;
    }

    public String getPays() {
        return this.pays;
    }

    public void setPays(String pays) {
        this.pays = pays;
    }

    public String getTel() {
        return this.tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String getVille() {
        return this.ville;
    }

    public void setVille(String ville) {
        this.ville = ville;
    }

    

    public String getDescription() {
        return this.description;
    }

    public void setNotes(String notes) {
        this.description = notes;
    }

   

  
    public boolean isSup18(int birthday) {
        boolean sup = true;
        Date today = new Date();
        int year = (int) today.getYear() + 1900;
        System.out.print("nam sinh=" + birthday);
        if ((birthday + 18) <= year) {
            sup = false;
        }
        return sup;
    }

    /**
     * @return the an
     */
    public String getAn() {
        return an;
    }

    /**
     * @param an the an to set
     */
    public void setAn(String an) {
        this.an = an;
    }

    /**
     * @return the jour
     */
    public String getJour() {
        return jour;
    }

    /**
     * @param jour the jour to set
     */
    public void setJour(String jour) {
        this.jour = jour;
    }

    /**
     * @return the mois
     */
    public String getMois() {
        return mois;
    }

    /**
     * @param mois the mois to set
     */
    public void setMois(String mois) {
        this.mois = mois;
    }

    /**
     * @return the numero
     */
    public String getNumero() {
        return numero;
    }

    /**
     * @param numero the numero to set
     */
    public void setNumero(String numero) {
        this.numero = numero;
    }

}
